package com.future.mayi.activity;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.future.baselib.utils.CommonUtils;
import com.future.mayi.R;

import butterknife.BindView;
import butterknife.OnClick;

public class EdtNickNameActivity extends BaseTitleActivity {
    @BindView(R.id.edt_name)
    EditText edtName;
    String name;

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("修改昵称");
        getRightText().setText("完成");
        getRightText().setTextColor(getResources().getColor(R.color.text_colorfe7712));
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_edt_nickname);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {
        if (getIntent() == null) return;
        name = getIntent().getStringExtra("nickName");
        if (TextUtils.isEmpty(name)) return;
        edtName.setText(name);
        edtName.setSelection(edtName.getText().length());
    }

    @Override
    protected void initListener() {
        getRightText().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(edtName.getText())) {
                    toast("昵称不能为空");
                    return;
                }
                if (!TextUtils.equals(name, edtName.getText())) {
                    Intent intent = new Intent();
                    intent.putExtra("nickName", edtName.getText().toString());
                    setResult(Activity.RESULT_OK, intent);
                }
                CommonUtils.hideKeyboard(edtName, EdtNickNameActivity.this);
                finish();
            }
        });
    }


}
